<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title>订单列表-WeAdmin Frame型后台管理系统-WeAdmin 1.0</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
	<link rel="stylesheet" href="../../css/font.css">
	<link rel="stylesheet" href="../../css/weadmin.css">
	<script src="../../lib/layui/layui.js" charset="utf-8"></script>
	<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
	<!--[if lt IE 9]>
	<script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
	<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
	<![endif]-->
</head>

<body>
<div class="weadmin-nav">
			<span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">节目管理</a>
        <a><cite>节目列表</cite></a>
      </span>
	<a class="layui-btn layui-btn-sm" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
		<i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="weadmin-body">

	<table class="layui-table" id="messageList" lay-filter="message">

	</table>
	<script type="text/html" id="barDemo">
		<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看演员</a>
		<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="add">添加演员</a>
		<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
		<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
	</script>
</div>
<script src="../../lib/jquery-2.1.1/jquery.js"></script>
<script src="../../js/admin.js"></script>
<script>
	layui.extend({
		admin: '{/}../../js/admin'
	});
	layui.use(['laydate', 'laypage', 'layer', 'table', 'carousel', 'upload', 'element', 'slider'], function() {
		var laydate = layui.laydate //日期
				, laypage = layui.laypage //分页
				, layer = layui.layer //弹层
				, table = layui.table //表格
				, upload = layui.upload //上传



		//执行一个 table 实例
		table.render({
			elem: '#messageList'
			, height: 500
			, url: '/message/queryAllByLimit' //数据接口
			,method: 'post'
			, title: '演员表'
			, page: true //开启分页
			, toolbar: 'default' //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
			, totalRow: false //开启合计行
			, cols: [[ //表头
				{type: 'checkbox', fixed: 'left'}
				, {field: 'id', title: 'ID', width: 100, sort: true, fixed: 'left', totalRowText: '合计：'}
				, {field: 'name', title: '节目名', width: 200}
				, {field: 'seqNumber', title: '节目序号', sort: true,width: 120,  totalRow: true}
				, {field: 'performerNumber', title: '演员个数', width: 100,  totalRow: true}
				, {field: 'createTime', title: '创建时间', width: 200,  totalRow: true}
				,{fixed: 'right', width: 300, align:'center', toolbar: '#barDemo'}
			]]
		});
		//监听头工具栏事件
		table.on('toolbar(message)', function(obj){
			var checkStatus = table.checkStatus(obj.config.id)
					,data = checkStatus.data; //获取选中的数据
			switch(obj.event){
				case 'add':
					WeAdminShow('添加节目','./add.html',600,400)
					break;
				case 'update':
					if(data.length === 0){
						layer.msg('请选择一行');
					} else if(data.length > 1){
						layer.msg('只能同时编辑一个');
					} else {
						localStorage.setItem("messageId",checkStatus.data[0].id)
						console.log(checkStatus.data[0])
						localStorage.setItem("message_name",checkStatus.data[0].name)
						localStorage.setItem("message_seq",checkStatus.data[0].seqNumber)
						WeAdminShow('编辑节目信息','./edit.html',600,400)

					}
					break;
				case 'delete':
					if(data.length === 0){
						layer.msg('请选择一行');
					} else {
						var ids=[]

						for(var i =0;i<data.length;i++){
							ids.push(data[i].id)
						}
						$.ajax({
							url: '/message/deleteByIds',
							data:{
								"ids":ids
							},
							success(res){
								layer.msg("删除成功")
								window.location.reload();//修改成功后刷新父界面
							},
							error(){

							}
						})
					}
					break;
			};
		});

		//监听行工具事件
		table.on('tool(message)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
			var data = obj.data //获得当前行数据
					,layEvent = obj.event; //获得 lay-event 对应的值
			if(layEvent === 'detail'){
				layer.msg('查看操作');
				localStorage.setItem("message_id_listPerformer",data.id)
				WeAdminShow('查看演员','./listPerformer.html',600,400)

			}else if(layEvent === 'add'){
				layer.msg("添加操作")
				localStorage.setItem("message_id_addPerformer",data.id)
				WeAdminShow('添加演员','./addPerformer.html',600,400)
			} else if(layEvent === 'del'){
				layer.confirm('真的删除行么', function(index){
					console.log(obj.data.id,index)
					$.ajax({
						url: '/message/delete',
						data:{
							"id":obj.data.id
						},
						success(res){
							obj.del(); //删除对应行（tr）的DOM结构
							layer.close(index);
						},
						error(){

						}
					})

				});
			} else if(layEvent === 'edit'){
				localStorage.setItem("messageId",data.id)
				localStorage.setItem("message_name",data.name)
				localStorage.setItem("message_seq",data.seqNumber)
				WeAdminShow('编辑节目信息','./edit.html',600,400)
			}
		});
	});
</script>
</body>

</html>